<template>
  <div class="replenish">
    <el-card style="margin-bottom: 20px;border: none;" shadow="never">
      <el-form :inline="true" :model="params" ref="replenishRef" class="form-inline">
        <el-form-item label="姓名" prop="username">
          <el-input v-model="params.username" placeholder="请输入姓名" clearable />
        </el-form-item>

        <el-form-item label="性别" prop="gender">
          <el-select
            v-model="params.gender"
            clearable
            placeholder="请选择性别"
          >
            <el-option
              v-for="item in genderOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="登记时间" prop="register_at">
          <el-date-picker
            v-model="params.register_at"
            clearable
            value-format="yyyy-MM-dd"
            type="date"
            class="ant-input"
            placeholder="请选择登记时间"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
          <el-button type="danger" @click="resettingSearch">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card style="margin-bottom: 20px;border: none;" shadow="never">
      <el-table
        v-loading="loading"
        :data="list"
        :header-cell-style="{background: '#f5f7fa'}"
        border
      >
        <el-table-column label="姓名" prop="username" align="center" />
        <el-table-column label="联系电话" prop="phone" align="center" />
        <el-table-column label="邮箱" prop="email" align="center" />
        <el-table-column label="性别" prop="gender" align="center">
          <template v-slot="{ row }">
            {{ row.gender === 1 ? '男' : row.gender===0?'女':'未填写' }}
          </template>
        </el-table-column>
        <el-table-column label="登记时间" prop="register_at" align="center" />
        <el-table-column label="操作" align="center">
          <template v-slot="{ row }">
            <el-button type="text" size="small" @click="handleReplenish(row)">
              <i class="el-icon-view" /> 补充
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        style="margin-top: 0; padding-bottom: 0;"
        :total="total"
        :limit="params.paginate"
        @pagination="handlePageChange"
      />
    </el-card>

  </div>
</template>
<script>
import { replenishmentInfo } from '@/api/v2/basic'
import Pagination from '@/components/Pagination'
export default {
  name: '',
  components: {
    Pagination
  },
  data() {
    return {
      list: [],
      params: {
        page: 1,
        paginate: 10,
        gender: null,
        username: '',
        register_at: ''
      },
      total: 0,
      loading: false,
      genderOptions: [
        { value: 1, label: '男' },
        { value: 0, label: '女' }
      ]
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getReplenishList()
    },

    async getReplenishList() {
      this.loading = true
      try {
        const res = await replenishmentInfo(this.params)
        this.list = res.data
        this.total = res.meta.total
        console.log('res --------->', res)
      } catch (error) {
        this.$message.error('信息获取失败！')
      } finally {
        this.loading = false
      }
    },

    handleReplenish(e) {
      console.log('e --------->', e)
      this.$router.push({
        path: `/personnel-files/show/${e.id}`,
        query: { tag_title: e.username + '-查看' }
      })
    },

    handlePageChange(e) {
      console.log('e --------->', e)
      this.params.page = e.page
      this.params.paginate = e.limit
      this.init()
    },
    handleSearch() {
      this.params.page = 1
      this.init()
    },
    resettingSearch(){
      this.$refs.replenishRef.resetFields();
    },
    resetParams() {
      this.params = this.$options.data().params
    }
  }
}
</script>
<style lang="scss" scoped>
.form-inline{
  .el-form-item{
    margin-bottom: 0px;
  }
}
.replenish {
  padding: 20px;
}
</style>
